package com.zitangkou.user.config;

import com.zitangkou.user.filter.UserInfoInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Deng Ningning
 * @version 1.0
 * @date 2020/9/16 22:19
 */
@Configuration
public class WebConfiguration implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInfoInterceptor());
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        String[] origins = {"http://localhost:8000"};
        registry.addMapping("*")
                .allowedHeaders("*")
                .allowedMethods("POST", "GET", "PUT", "DELETE")
                .allowedOrigins(origins)
                .allowCredentials(true)
                .maxAge(3600);
    }
}
